package com.gtlab1207.br_security.services;

import com.gtlab1207.br_security.models.dao.EncryptionDao;
import com.gtlab1207.br_security.models.domain.Encryption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class EncryptionService {

    @Autowired
    private EncryptionDao encryptionDao;

    @Transactional
    public int addEncryption(Encryption record) {
        Encryption beforeRecord = encryptionDao.selectEncryptionById(record.getProvideOrg(), record.getTopicId());
        if(beforeRecord!=null){
            encryptionDao.deleteEncryption(record.getProvideOrg(), record.getTopicId());
        }
        return encryptionDao.addEncryption(record);
    }
    @Transactional
    public int deleteEncryption(String provideOrg, String topicId) {
        return encryptionDao.deleteEncryption(provideOrg, topicId);

    }
    @Transactional
    public int updateEncryption(Encryption record) {
        return encryptionDao.updateEncryption(record);

    }

    public List<Encryption> selectAll() {
        return encryptionDao.selectAll();

    }

    public List<Encryption> selectEncryptionByCondition(Encryption condition) {
        return encryptionDao.selectEncryptionByCondition(condition);
    }

    public Encryption selectEncryptionById(String provideOrg, String topicId) {
        return encryptionDao.selectEncryptionById(provideOrg,topicId);
    }


}
